<template>
	<!-- <button @click="toWorkes" style="width: 50%;margin: 50rpx auto;">点击进入系统</button> -->
	<view style="position: relative;">
		<image class="bacc" src="https://beerb.jhsaas.com.cn:19000/static/beer/index2.png"></image>
		<view class="bigBox">
			<view class="infoBox" v-if="loginShow" @click="toLogin">
				<view class="noLogin">
					请登录
				</view>
			</view>
			<view class="infoBox" @click="toUserInfo" v-else>
				<image class="atr" :src="avatar"></image>
				<view class="info">
					<view class="nameBox">
						<view class="name">
							{{name}}
						</view>
						<image class="alter" src="../../static/images/minde/address.png"></image>
					</view>
					<view class="sexBox">
						ID:{{id}} 丨 <text v-if="sex==1">男</text><text v-else-if="sex==2">女</text><text v-else>保密</text>
					</view>
				</view>
			</view>
			<view class="otherBox">
				<view class="title">
					进货订单
				</view>
				<view class="iconBox">
					<view class="icon" @click="toOrder(1)">
						<view class="bugIcon" v-show="replenNumber.allCount">
							{{replenNumber.allCount}}
						</view>
						<image class="iconImage" src="@/static/images/work/order1.png">
						</image>
						<view class="iconTitle">
							全部
						</view>
					</view>
					<view class="icon margins" @click="toOrder(3)">
						<view class="bugIcon" v-show="replenNumber.deliveredCount">
							{{replenNumber.deliveredCount}}
						</view>
						<image class="iconImage" src="@/static/images/work/order2.png"></image>
						<view class="iconTitle">
							待收货
						</view>
					</view>
					<view class="icon margins" @click="toOrder(4)">
						<view class="bugIcon" v-show="replenNumber.completedCount">
							{{replenNumber.completedCount}}
						</view>
						<image class="iconImage" src="@/static/images/work/order3.png"></image>
						<view class="iconTitle">
							已收货
						</view>
					</view>
					<view class="icon margins" @click="toOrder(5)">
						<view class="bugIcon" v-show="replenNumber.afterSaleCount">
							{{replenNumber.afterSaleCount}}
						</view>
						<image class="iconImage" src="@/static/images/work/order4.png"></image>
						<view class="iconTitle">
							售后
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="otherBox2 padding_b">
			<view class="title2">
				商户管理
			</view>
			<view class="otherLi" @click="toMyMeal">
				<image class="otherImg" src="@/static/images/work/meal2.png"></image>
				<view class="otherTxt">
					我的套餐
				</view>
			</view>
			<!-- <view class="otherLi" @click="toStock">
				<image class="otherImg" src="@/static/images/work/stock.png"></image>
				<view class="otherTxt">
					套餐库存
				</view>
			</view> -->
			<!-- <view class="otherLi" @click="toNotes">
				<image class="otherImg" src="@/static/images/work/table2.png"></image>
				<view class="otherTxt">
					桌牌申请记录
				</view>
			</view> -->
			<view class="otherLi" @click="toAddress">
				<image class="otherImg" src="@/static/images/work/address.png"></image>
				<view class="otherTxt">
					地址管理
				</view>
			</view>
		</view>
		<view class="otherBox">
			<view class="title">
				更多功能
			</view>
			<view class="iconBox">
				<view class="icon margins2" @click="toOther">
					<image class="iconImage" src="@/static/images/index/house.png"></image>
					<view class="iconTitle">
						线上商城
					</view>
				</view>
				<view class="icon margins2" @click="toAddUs" v-if="!containsValueInArray([1])">
					<image class="iconImage" src="@/static/images/index/in.png"></image>
					<view class="iconTitle">
						成为商户
					</view>
				</view>
				<view class="icon margins2" @click="apply" v-if="!containsValueInArray([2,3])">
					<image class="iconImage" src="@/static/images/index/manage.png"></image>
					<view class="iconTitle">
						成为业务员
					</view>
				</view>
				<!-- <view class="icon margins2" @click="toWorkes" v-if="containsValueInArray([1])">
					<image class="iconImage" src="../../static/images/minde/shop.png"></image>
					<view class="iconTitle">
						商户管理
					</view>
				</view> -->
				<view class="icon" @click="toWorkes2" v-else>
					<image class="iconImage" src="../../static/images/minde/user.png"></image>
					<view class="iconTitle">
						业务员管理
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="show" :closeable="true" :safeAreaInsetTop="true" :safeAreaInsetBottom="false" :round="10"
			mode="center" @close="close" @open="open">
			<view class="pupBox">
				<image class="pupImg" :src="menubar.qrCodeUrl"></image>
				<view class="titMsg">
					请截图保存图片，等待业务员来电
				</view>
				<view class="pupName">
					姓名：{{menubar.name}}
				</view>
				<view class="pupName">
					电话：{{menubar.phone}}
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getCount,
		applyMerchantsType,
		applyMerchants,
		salse,
		applySales
	} from "@/api/wine/wine.js"
	export default {
		data() {
			return {
				avatar: '',
				sex: '1',
				id: '',
				name: '',
				phone: '',
				loginShow: true,
				allOrder: 0, //全部订单
				awitOrder: 0, //待取酒
				accOrder: 0, //已取酒
				reduceOrder: 0, //已退单
				menubar: {}, //申请商户的信息
				show: false,
				replenNumber: {}, //补货数量
			}
		},
		onShow() {
			this.avatar = this.$store.getters.avatar
			let id = this.$store.getters.id
			if (id) {
				this.id = id
				this.loginShow = false
				// this.getOrderCount()
				this.getNumber()
			}
			let sex = this.$store.getters.sex
			if (sex) {
				this.sex = sex
			} else {
				this.sex = 3
			}
			this.name = this.$store.getters.name
			this.phone = this.$store.getters.mobile
			this.$store.dispatch('GetInfo').then(res => {
				// console.log('111')
			})
		},
		methods: {
			//获得店铺订单数量
			getNumber() {
				let that = this
				getCount({}).then(response => {
					if (response.code == 0) {
						// uni.hideLoading()
						that.replenNumber = response.data
					}
				})
			},
			//跳转地址管理
			toAddress() {
				if(this.containsValueInArray([1])){
					this.$tab.navigateTo('/pagesA/address/address')
				}else{
					uni.$u.toast('成为商户后重试')
				}
			},
			//跳转我的套餐
			toMyMeal() {
				if(this.containsValueInArray([1])){
					this.$tab.navigateTo('/pagesA/myMeal/myMeal')
				}else{
					uni.$u.toast('成为商户后重试')
				}
			},
			//跳转库存
			toStock() {
				if(this.containsValueInArray([1])){
					this.$tab.navigateTo('/pagesA/stock/stock')
				}else{
					uni.$u.toast('成为商户后重试')
				}
			},
			// 申请成为业务员逻辑
			apply() {
				let that = this
				if (this.name && this.phone) {
					salse().then(response => {
						uni.hideLoading()
						if (response.code == 0) {
							if (response.data) {
								if (response.data.processStatus == 0) {
									uni.showModal({
										title: '提示',
										content: '待审核',
										success: function(res) {
											if (res.confirm) {
												// console.log('用户点击确定');
											} else if (res.cancel) {
												// console.log('用户点击取消');
											}
										}
									})
								} else if (response.data.processStatus == 1) {
									uni.showModal({
										title: '提示',
										content: '审核已通过',
										success: function(res) {
											if (res.confirm) {
												// console.log('用户点击确定');
											} else if (res.cancel) {
												// console.log('用户点击取消');
											}
										}
									})
								} else {
									uni.showModal({
										title: '提示',
										content: response.data.processOpinion + ';请点击确定再次发起申请',
										success: function(res) {
											if (res.confirm) {
												applySales().then(response => {
													uni.hideLoading()
													if (response.code == 0) {
														uni.$u.toast('成功提交申请')
													}
												})
											} else if (res.cancel) {
												// console.log('用户点击取消');
											}
										}
									})
								}
							} else {
								applySales().then(response => {
									uni.hideLoading()
									if (response.code == 0) {
										uni.$u.toast('成功提交申请')
									}
								})
							}
						}
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '请点击头像完善个人信息',
						success: function(res) {
							if (res.confirm) {
								// that.$tab.reLaunch('/pages/mine/index')
							} else if (res.cancel) {
								// console.log('用户点击取消');
							}
						}
					})
				}
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				this.menubar = {}
				// console.log('close');
			},
			//跳转加入我们
			toAddUs() {
				let that = this
				uni.showLoading({
					title: '加载中'
				})
				if (that.name && that.phone) {
					applyMerchantsType().then(response => {
						if (response.code == 0) {
							if (response.data) {
								if (!response.data.businessId) {
									uni.hideLoading()
									that.menubar = response.data
									that.show = true
								} else {
									this.$tab.navigateTo('/pages/addUs/addUs?businessId=' + response.data
										.businessId)
								}
							} else {
								//null表示没有申请，发起申请
								applyMerchants().then(res => {
									if (res.data) {
										applyMerchantsType().then(res2 => {
											if (res2.code == 0) {
												uni.hideLoading()
												that.menubar = res2.data
												that.show = true
											}
										})
									}
								})
							}
						}
					})
				} else {
					uni.hideLoading()
					uni.showModal({
						title: '提示',
						content: '请点击头像完善个人信息',
						success: function(res) {
							if (res.confirm) {
								// that.$tab.reLaunch('/pages/mine/index')
							} else if (res.cancel) {
								// console.log('用户点击取消');
							}
						}
					})
				}
			},
			//跳转商城
			toOther() {
				this.$tab.navigateTo('/pages/bigImg/bigImg')
			},
			// getOrderCount() {
			// 	let that = this
			// 	getCount({
			// 		type: 1
			// 	}).then(response => {
			// 		that.allOrder = response.data.allCount
			// 		that.awitOrder = response.data.deliveredCount
			// 		that.accOrder = response.data.completedCount
			// 		that.reduceOrder = response.data.afterSaleCount
			// 	})
			// },
			toUserInfo() {
				this.$tab.navigateTo('/pages/userInfo/userInfo')
			},
			toOrder(e) {
				if(this.containsValueInArray([1])){
					this.$tab.navigateTo('/pagesA/replenOrder/replenOrder?type=' + e)
				}else{
					uni.$u.toast('成为商户后重试')
				}
			},
			toLogin() {
				this.$tab.navigateTo('/pagesA/login')
			},
			// toWorkes() {
			// 	this.$tab.navigateTo('/pagesA/work/index')
			// },
			toWorkes2() {
				this.$tab.navigateTo('/pagesA/staff/staff')
			},
			//判断是否含有指定身份的函数
			containsValueInArray(value) {
				let array = this.$store.getters.tagIds
				let ret = false
				value.forEach(item => {
					if (array.includes(item)) {
						ret = true
					}
				});
				return ret;
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F5F5F5;
	}

	.bacc {
		position: absolute;
		width: 750rpx;
		height: 426rpx;
		top: 0;
		z-index: -1;
	}

	.bigBox {
		width: 690rpx;
		margin: 0 auto;
		overflow: hidden;
	}

	.noLogin {
		width: 690rpx;
		height: 250rpx;
		text-align: center;
		line-height: 250rpx;
		font-size: 30rpx;
	}

	.infoBox {
		width: 690rpx;
		height: 250rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: 272rpx 0 30rpx 0;
		position: relative;
		border: 1px solid white;
	}

	.atr {
		width: 156rpx;
		height: 156rpx;
		border-radius: 50%;
		position: absolute;
		top: -78rpx;
		left: 50rpx;
		background-color: white;
	}

	.info {
		width: 690rpx;
		height: 150rpx;
		margin-top: 100rpx;
	}

	.nameBox {
		width: 590rpx;
		height: 50rpx;
		margin: 0 auto;
		line-height: 50rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.name {
		max-width: 500rpx;
		height: 50rpx;
		font-weight: bold;
		font-size: 32rpx;
		color: #333333;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.alter {
		width: 28rpx;
		height: 28rpx;
		margin-left: 20rpx;
	}

	.sexBox {
		width: 590rpx;
		height: 50rpx;
		line-height: 50rpx;
		margin: 0 auto;
		font-size: 20rpx;
		color: #999999;
	}

	.otherBox {
		width: 690rpx;
		height: 250rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: 20rpx auto 0 auto;
		overflow: hidden;
	}

	.title {
		width: 630rpx;
		height: 50rpx;
		line-height: 50rpx;
		margin: 30rpx auto;
		font-weight: bold;
		font-size: 32rpx;
		color: #333333;
	}

	.iconBox {
		width: 590rpx;
		height: 120rpx;
		margin: 0 auto;
		display: flex;
	}

	.icon {
		width: 100rpx;
		height: 120rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: center;
		position: relative;
	}

	.iconImage {
		width: 64rpx;
		height: 64rpx;
	}

	.bugIcon {
		min-width: 30rpx;
		height: 30rpx;
		text-align: center;
		line-height: 30rpx;
		font-size: 20rpx;
		color: white;
		border-radius: 15rpx;
		background-color: red;
		position: absolute;
		top: 0;
		right: 0;
	}

	.iconTitle {
		width: 140rpx;
		height: 40rpx;
		font-size: 28rpx;
		color: #333333;
		text-align: center;
	}

	.margins2 {
		margin-right: 60rpx;
	}

	.margins {
		margin-left: 60rpx;
	}

	/* 弹出层 */
	.pupBox {
		width: 500rpx;
		height: 650rpx;
	}

	.pupImg {
		width: 490rpx;
		height: 490rpx;
		display: block;
		margin: 0 auto;
	}

	.titMsg {
		width: 500rpx;
		height: 20rpx;
		line-height: 20rpx;
		font-size: 25rpx;
		text-align: center;
		color: #E84E22;
		margin-top: 20rpx;
	}

	.pupName {
		width: 500rpx;
		height: 30rpx;
		line-height: 30rpx;
		text-align: center;
		font-size: 30rpx;
		margin-top: 20rpx;
	}

	.bigImage {
		width: 690rpx;
		height: 1072rpx;
		margin: 20rpx auto;
		display: block;
	}

	.otherBox2 {
		width: 690rpx;
		min-height: 250rpx;
		background: #FFFFFF;
		margin: 20rpx auto 0 auto;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
	}

	.title2 {
		width: 630rpx;
		height: 50rpx;
		line-height: 50rpx;
		margin: 30rpx auto;
		font-weight: bold;
		font-size: 32rpx;
		color: #333333;
	}

	.padding_b {
		padding-bottom: 30rpx;
	}

	.otherLi {
		width: 630rpx;
		height: 108rpx;
		border-bottom: 2rpx solid #F1F1F1;
		margin: 0 auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.otherLi:last-child {
		border: none;
	}

	.otherImg {
		width: 48rpx;
		height: 48rpx;
	}

	.otherTxt {
		width: 550rpx;
		height: 108rpx;
		line-height: 108rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #333333;
	}
</style>